<?php


defined('IN_IA') or exit('Access Denied');

class Ymq_changdiModuleSite extends WeModuleSite {

    // 转发所有请求到tp框架处理
    public function __call($name, $arguments) {
        global $_GPC,$_W;

        $data = [
            'we7_uid' => $_W['uid'],
            'we7_uniacid' => $_W['uniacid'],
        ];
        

        $str = '';
        $str .= (new self)->generate_rand_str(16);
        $str .= base64_encode(json_encode($data));
        $str .= (new self)->generate_rand_str(16);

        $url = $_W['siteroot'].'addons/ymq_changdi/public/backend.php/index/login?_session='. $str;
        header('Location: '. $url);exit();
    }

    public function generate_rand_str($length = 8, $type = 0) {
        $a = 'abcdefghijklmnopqrstuvwxyz';
        $A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $n = '0123456789';

        switch ($type) {
            case 1: $chars = $a; break;
            case 2: $chars = $A; break;
            case 3: $chars = $n; break;
            case 4: $chars = $a.$A; break;
            case 5: $chars = $a.$A.$n; break;
            default: $chars = $a.$n;
        }

        $str = '';
        for ($i = 0; $i < $length; $i++) {
            $str .= $chars[ mt_rand(0, strlen($chars) - 1) ];
        }
        return $str;
    }
}
